492A - Vanya and Cubes - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

n=int(input())
i=1
c=0
j=2
while(n>=i):
    n=n-i
    c+=1
    i+=j
    j+=1
print(c)

C++ Code:

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include<string>
#include<map>
using namespace std;

long long factorial(long long n)
{
	if (n == 1)
		return 1;
	return n * factorial(n - 1);
}

vector<int> primeFactorization(int n)
{
	vector<int> v;
	for (int i = 2;i * i <= n;i++)
	{
		if (n % i == 0)
		{
			while (n % i == 0)
			{
				n /= i;
				v.push_back(i);
			}
		}
	}
	if (n != 1)
		v.push_back(n);
	return v;
}

long long  GCD(long long  n, long long k)
{
	return k == 0 ? n : GCD(k, n % k);
}

long long  LCM(long long  n, long long k)
{
	return n / GCD(n, k) * k;
}

long long sum(long long a)
{
	return (a * (a + 1)) / 2;
}

long long oddSum(long long a)
{
	return  ((a + 1) / 2) * ((a + 1) / 2);
}

long long evenSum(long long a)
{
	return sum(a) - oddSum(a);
}

bool isPrime(long long a)
{
	if (a <= 1)
		return false;
	for (long long i = 2;i * i <= a;i++)
	{
		if (a % i == 0)
		{
			return 0;
		}
	}
	return true;
}

vector<long long>Divisiors(long long n)
{
	vector<long long>v;
	for (long long i = 1;i * i <= n;i++)
	{
		if (n % i == 0)
		{
			if (n / i == i)
				v.push_back(i);
			else
			{
				v.push_back(i);
				v.push_back(n / i);
			}
		}
	}
	return v;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,sum=0,total=0;
	cin >> n ;
	int ctr = 0;
	for (int i = 1;i <= n;i++)
	{
		if (total> n)
			break;
		
		
		sum+= i ;
		total += sum;
		ctr++;
		//cout << sum << "\n";
	}
	if (ctr <=1)
		cout << "1";
	else
	cout << ctr-1;
	return 0;
}


Comments

Submit
0 Comments
More Questions

903C - Boxes Packing
887A - Div 64
755B - PolandBall and Game
808B - Average Sleep Time
1515E - Phoenix and Computers
1552B - Running for Gold
994A - Fingerprints
1221C - Perfect Team
1709C - Recover an RBS
378A - Playing with Dice
248B - Chilly Willy
1709B - Also Try Minecraft
1418A - Buying Torches
131C - The World is a Theatre
1696A - NIT orz
1178D - Prime Graph
1711D - Rain
534A - Exam
1472A - Cards for Friends
315A - Sereja and Bottles
1697C - awoo's Favorite Problem
165A - Supercentral Point
1493A - Anti-knapsack
1493B - Planet Lapituletti
747B - Mammoth's Genome Decoding
1591C - Minimize Distance
1182B - Plus from Picture
1674B - Dictionary
1426C - Increase and Copy
520C - DNA Alignment